package com.example.shopping_web_back.mapper;

import com.example.shopping_web_back.pojo.ShoppingCar;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ShoppingCarMapper {

    @Insert("insert into shoppingweb.shopping_car(customer_name, business_name, goods_name, goods_num, is_purchase, image, price) VALUE "
            +"(#{customerName}, #{businessName}, #{goodsName}, #{goodsNum}, #{isPurchase}, #{image}, #{price})")
    void addGoods(ShoppingCar shoppingCar);

    @Update("update shoppingweb.shopping_car set goods_num=#{num}, is_purchase=#{purchase} where goods_name=#{shoppingCar.goodsName} and business_name=#{shoppingCar.businessName} and customer_name=#{shoppingCar.customerName}")
    void updateGoods(ShoppingCar shoppingCar, Integer num, Boolean purchase);

    @Delete("delete from shoppingweb.shopping_car where customer_name=#{customerName} and business_name=#{businessName} and goods_name=#{goodsName}")
    void deleteGoods(ShoppingCar shoppingCar);

    @Select("select * from shoppingweb.shopping_car where customer_name=#{customerName}")
    List<ShoppingCar> list(String customerName);

    @Select("select * from shoppingweb.shopping_car where customer_name=#{customerName} and business_name=#{businessName} and goods_name=#{goodsName}")
    ShoppingCar findGoods(ShoppingCar shoppingCar);
}
